﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Licenta1;
using System.Collections;
using Licenta1.Shapes;
using Licenta1.RayTracer;

namespace Licenta1.Expressions
{
    [Serializable]
    class ObjectExpression : Expression
    {
        string objName;
        Expression parameters;
        Shape shape;
        
        public ObjectExpression(Context con, String name, Expression expr)
            : base(con)
        {
            this.objName = name;
            parameters = expr;
            shape = null;
        }

        public Shape createObject(string objName, Expression parameters)
        {
            switch (objName)
            {
                case "point": { return new Point(context, parameters); }
                case "line": { return new Line(context, parameters); }
                case "polygon": { return new Polygon(context, parameters); }
                case "rectangle": { return new Rectangle(context, parameters); }
                case "square": { return new Square(context, parameters); }
        //        case "bezier": { return new Bezier(); break; }
                case "ellipse": { return new Ellipse(context, parameters); }
                case "circle": { return new Circle(context, parameters); }
                case "cube": { return new Cube(context, parameters); }
                case "sphere": { return new Sphere(context, parameters); }
                case "plane": { return new Plane(context, parameters); }
                case "csg": { return new Csg(context, parameters); }
                default:
                    return null;
            }
        }

        public override object Value
        {
            get
            {
                if (shape == null)
                    shape = createObject(objName,parameters);

                return shape.Value;
            }
        }

        public string NAME
        {
            get { return objName; }
        }

        public Expression PARAMETERS
        {
            get { return parameters; }
        }

        public Shape SHAPE
        {
            get { return shape; }
            set { shape = value; }
        }

    }
}